<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta name="screen-orientation" content="portrait">
    <meta name="x5-orientation" content="portrait">
    <title>订单查询</title>
    <link rel="stylesheet" href="../../styles/h5/reset.min.css"/>
    <link rel="stylesheet" href="../../styles/h5/errortankuang.css"/>
    <!--以上为公共css样式-->
    <link rel="stylesheet" href="../../styles/h5/fund.css"/>
    <link rel="stylesheet" href="../../styles/h5/dropload.css"/>

    <script charset="utf-8" type="text/javascript" src="../../scripts/h5/jquery-1.9.1.min.js"></script>
    <script charset="utf-8" type="text/javascript" src="../../scripts/h5/jquery.modal.js"></script>
    <!--以上为公共js文件-->
</head>
<body>
<div class="zz-all-jj">
    <ul>
        <li>
            <span class="zz-selectSpan-jj">全部交易</span>
            <select class="zz-transaction-jj" id="selectProfit" name="">
                <option value="">全部交易</option>
                <option value="purchase">转入</option>
                <option value="redemption">转出</option>
            </select>
            <span class="zz-downNormal-jj"></span>
        </li>
        <li class="zz-selectLi-jj">
            <span class="zz-selectSpan-jj">全部产品</span>
            <select class="zz-transaction-jj" id="selectProduct" name="">
                <option value="">全部产品</option>
                <!--<option value="">招商招钱宝产品Aaaaaaa</option>-->
            </select>
            <span class="zz-downNormal-jj"></span>
        </li>
        <li>
            <span class="zz-selectSpan-jj">所有月份</span>
            <select class="zz-transaction-jj" id="selectMonth" name="">
                <option value="">所有月份</option>
                <!--<option value="">2017年9月</option>-->
            </select>
            <span class="zz-downNormal-jj"></span>
        </li>
    </ul>
</div>
<div class="zz-all-list-jj">
    <!--<span class="zz-month-list-jj">2017年8月</span>-->
    <!--<ul>-->
    <!--<li>-->
    <!--<p class="zz-orderList">-->
    <!--<span class="zz-order">【转入】订单号123456789</span>-->
    <!--<span class="zz-money-jj zz-color-jj">+100000.12</span>-->
    <!--</p>-->
    <!--<p class="zz-timeList clear">-->
    <!--<span class="zz-everyday">结算款每日自动申购</span>-->
    <!--<span class="zz-time">2017-09-12</span>-->
    <!--</p>-->
    <!--</li>-->
    <!--</ul>-->
</div>

<!-- <input type="button" class="footer zz-look-more" value="加载更多"/> -->
</body>
<script charset="utf-8" type="text/javascript" src="../../scripts/h5/utils.js"></script>
<script charset="utf-8" type="text/javascript" src="../../scripts/h5/index.js"></script>
<script charset="utf-8" type="text/javascript" src="../../scripts/h5/dropload.min.js"></script>
<script charset="utf-8" type="text/javascript">
    $(".zz-all-jj ul li select").change(function () {
        var selectVal = $(this).find("option:selected").text();
        $(this).prev(".zz-selectSpan-jj").html(selectVal);
    });

    var $selectProfit = $("#selectProfit");
    var $selectMonth = $("#selectMonth");
    var $selectProduct = $("#selectProduct");
    var $allList = $(".zz-all-list-jj");
    var $lookMore = $(".zz-look-more");
    var $body = $("body");
    var choiceMonth = "";
    var yearMonth1="";
    var yearMonth2="";
    var yearMonth3="";
    var resultList = "";
    var yearMonth = "";
    var divisionFlag = "";
    var fundNo = "";
    var choiceMonthArr = '';
    var timer = '';
    var result = '';
    var data = '';
    var profitType = '';
    var profitMsg = '';
    var flag = true;
    var num = 0;
    //初始化月份
    $.ajax({
        url: utils.ajaxUrl()+"h5/fund/opendAccount/getYearMonths",
        data: {
            months: 3
        },
        async: false,
        type: 'get',
        success: function (res) {
            var res = JSON.parse(res);
            console.log(res);
            if (res && res.retCode == '0000') {
                var months = res["resultList"];
                yearMonth1 = utils.interceptDate(months[0],"-","year");
                yearMonth2 = utils.interceptDate(months[1],"-","year");
                yearMonth3 = utils.interceptDate(months[2],"-","year");
                var monthsStr = '';
                for (var i = 0; i < months.length; i++) {
                    var curMonths = months[i];
                    var curMonthsArr = months[i].split("-");
                    var yearMonths = curMonthsArr[0] + "年" + curMonthsArr[1] + "月";
                    monthsStr += '<option value="' + curMonths + '">' + yearMonths + '</option>';
                }
                $selectMonth.append(monthsStr);
                //choiceMonthFun();
                //ajaxInitial();
            } else {
                utils.error("sx.png", "啊哦，数据异常");
            }
        },
        error: function () {
            utils.error("wlyc.png", "啊哦，连接不到网络呢");
        }
    });

    //初始化产品
    $.ajax({
        url: utils.ajaxUrl()+"/h5/fund/opendAccount/getFundList",
        async: false,
        type: 'get',
        success: function (res) {
            var res = JSON.parse(res);
            console.log(res);
            if (res && res.retCode == '0000') {
                var product = res["resultList"];
                var productStr = '';
                for (var key in product) {
                    productStr += '<option value="' + key + '">' + product[key] + '</option>';
                }
                $selectProduct.append(productStr);
                //choiceMonthFun();
                //console.log(yearMonth);
                //ajaxInitial();
            } else {
                utils.error("sx.png", "啊哦，数据异常");
            }
        },
        error: function () {
            utils.error("wlyc.png", "啊哦，连接不到网络呢");
        }
    });

    function choiceSelect() {
        choiceMonth = $selectMonth.find("option:selected").attr("value");
        if (choiceMonth != "") {
            choiceMonthArr = choiceMonth.split("-");
            yearMonth = choiceMonthArr[0] + choiceMonthArr[1];
        } else {
            yearMonth = yearMonth1;
        }
        fundNo = $selectProduct.find("option:selected").attr("value");
        divisionFlag = $selectProfit.find("option:selected").attr("value");
    }

    function bindHTML() {
        result = '';
        if (data.resultList != null && data.resultList.length > 0) {
	        var yearsMonths = utils.interceptDate(data.resultList[0].orderDate, "-", "year", "年", "月");
	        result += '<span class="zz-month-list-jj">' + yearsMonths + '</span>';
	        for (var i = 0; i < data.resultList.length; i++) {
	            var curData = data.resultList[i];
	            switch (curData.servType) {
	                case "801":
	                    profitType = "转入";
	                    profitMsg = "结算款每日自动申购";
	                    break;
	                case "802":
	                    profitType = "转出";
	                    profitMsg = "普通转出";
	                    break;
	                case "803":
	                    profitType = "转出";
	                    profitMsg = "快速转出";
	                    break;
	            }
	
	            result += '<ul>';
	            result += '<li>';
	            result += '<p class="zz-orderList">';
	            result += '<span class="zz-order">【' + profitType + '】订单号' + curData.orderId + '</span>';
	            if (curData.servType == 801) {
	                result += '<span class="zz-money-jj zz-color-jj">+' + curData.amountY + '</span>';
	            } else {
	                result += '<span class="zz-money-jj">-' + curData.amountY + '</span>';
	            }
	            result += '</p>';
	            result += '<p class="zz-timeList clear">';
	            result += '<span class="zz-everyday">' + profitMsg + '</span>';
	            result += '<span class="zz-time">' + curData.orderDate + '</span>';
	            result += '</p>';
	            result += '</li>';
	            result += '</ul>';
	        }
		} else {
			result = '';
		}
		
        if (flag) {
            $allList.html(result);
        } else {
            $allList.append(result);
        }
    }

    var noDataStr = '<div class="dropload-noData">暂无数据</div>';
    var loadStr = '<div class="dropload-load"><span class="loading"></span>加载中...</div>';
    var loadSt = '<div class="dropload-load">↑上拉加载</div>';

    ajaxList();
    function ajaxList() {
        choiceMonth = $selectMonth.find("option:selected").attr("value");
        if (choiceMonth != "") {
            choiceMonthArr = choiceMonth.split("-");
            yearMonth = choiceMonthArr[0] + choiceMonthArr[1];
        } else {
            if(num==0){
                yearMonth = yearMonth1;
            }else if(num==1){
            	
                yearMonth = yearMonth2;
            }else if(num==2){
                yearMonth = yearMonth3;
            }else{
            	window.onscroll = '';
            	if ($body.children(".dropload-noData").length == 0) {
                    $("body").append(noDataStr);
                }
                $body.children(".dropload-load").remove();
                //$lookMore.hide();
            	return
            }
        }
        
        num++;
		//alert(num);
		//alert(yearMonth)
        $.ajax({
            type: 'GET',
            url: utils.ajaxUrl()+"h5/fund/opendAccount/getFundTradeList",
            data: {
                divisionFlag: divisionFlag,
                fundNo: fundNo,
                yearMonth: yearMonth
            },
            dataType: 'json',
            success: function (res) {
                //console.log(res);
                //var data = JSON.parse(res);
                
                data = res;
                if (data.retCode == "0000") {
                	choiceMonth = $selectMonth.find("option:selected").attr("value");
                	divisionFlag = $selectProfit.find("option:selected").attr("value");
                	console.log(num);
                    if (data.resultList ==null || data.resultList.length == 0) {
                    	
                    	if(choiceMonth == ""){
                    	
	                    	if(num == 1){
	                    		//alert(yearMonth +"===kong1")
	                            bindHTML();
	                            
	                            ajaxList();
	                            return
	                        }
	                        if(num == 2){
	                        	//alert(yearMonth +"===kong2")
	                            bindHTML();
	                            ajaxList();
	                            return
	                        }
	                        
                    	}else{
                    	 	$allList.html("");
                    	}
                        
                        if ($body.children(".dropload-noData").length == 0) {
                            $("body").append(noDataStr);
                        }
                        $body.children(".dropload-load").remove();
                        bindHTML();
                        return;
                    } else {
                        $("body").children(".dropload-noData").remove();
                    }
                    bindHTML();
                    
                    if(num ==3){
                       	if ($body.children(".dropload-noData").length == 0) {
                           	$("body").append(noDataStr);
                       	}
                       	$body.children(".dropload-load").remove();
                       	return
                    }
                    
                    if ($(".zz-all-list-jj").children().length < 11 && choiceMonth =="") {
                        flag = false;
                        if(num == 1){
                        	//alert(yearMonth +"===you1")
                            ajaxList();
                            return
                        }
                        if(num == 2){
                        	//alert(yearMonth +"===you2")
                            ajaxList();
                            return
                        }
                        
                    }
                    
                    if (choiceMonth == "") {
                        yearMonth = "";
                    }
                    
                    if (yearMonth == "") {
                        if ($(".zz-all-list-jj").children().length > 10) {
                            $("body").append(loadSt);
                            onscrollFun();
                        }else{
                            $("body").children(".dropload-load").remove();
                        }
                    } else {
                        window.onscroll = '';
                        if ($body.children(".dropload-noData").length == 0) {
                            $body.append(noDataStr);
                        }
                        $body.children(".dropload-load").remove();
                    }

                } else {
                    utils.error("sx.png", "啊哦，数据异常");
                }
            },
            error: function () {
                utils.error("wlyc.png", "啊哦，连接不到网络呢");
            }
        });
    }
    //获取滚动条当前的位置
    function getScrollTop() {
        var scrollTop = 0;
        if (document.documentElement && document.documentElement.scrollTop) {
            scrollTop = document.documentElement.scrollTop;
        }
        else if (document.body) {
            scrollTop = document.body.scrollTop;
        }
        return scrollTop;
    }

    //获取当前可视范围的高度
    function getClientHeight() {
        var clientHeight = 0;
        if (document.body.clientHeight && document.documentElement.clientHeight) {
            clientHeight = Math.min(document.body.clientHeight, document.documentElement.clientHeight);
        }
        else {
            clientHeight = Math.max(document.body.clientHeight, document.documentElement.clientHeight);
        }
        return clientHeight;
    }

    //获取文档完整的高度
    function getScrollHeight() {
        return Math.max(document.body.scrollHeight, document.documentElement.scrollHeight);
    }

    function onscrollFun() {
    	
        window.onscroll = function () {
        	//console.log(getScrollTop() + getClientHeight()+2);
        	//console.log(getScrollHeight());
        	//console.log((getScrollTop() + getClientHeight()) == getScrollHeight());
        	
            if (getScrollTop() + getClientHeight() == getScrollHeight() || getScrollTop() + getClientHeight()+2 > getScrollHeight()) {
                
                //console.log(num);
                if ($body.children(".dropload-load").length != 0) {
                    $body.children(".dropload-load").html(loadStr)
                }
                flag = false;
                //ajax从这里开始
                setTimeout(function () {
                    ajaxList();
                    $("body").children(".dropload-load").remove();
                    //$("body").append(str);
                }, 200);
            }
        };
    }

    $(function () {
        $selectMonth.change(function () {
            num = 0;
            choiceSelect();
            flag = true;
            $allList.html("");
            ajaxList();
        });
    });
    $(function () {
        $selectProduct.change(function () {
            num = 0;
            choiceSelect();
            flag = true;
            $allList.html("");
            ajaxList();
        });
    });
    $(function () {
        $selectProfit.change(function () {
            num = 0;
            choiceSelect();
            flag = true;
            $allList.html("");
            ajaxList();
        });
    });

    /* $lookMore.click(function () {
        num++;
        choiceSelect();
        if ($(".zz-all-list-jj").children().length > 9) {
            return
        }
        flag = false;
        ajaxList();
    }); */
</script>
</html>